package punctuatedEquilibriumTest;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import mockit.Deencapsulation;

import org.junit.Before;
import org.junit.Test;

import punctuatedEquilibrium.Individual;
import punctuatedEquilibrium.IndividualFactory;
import punctuatedEquilibrium.IndividualParameterFactory;
import punctuatedEquilibrium.IndividualParameters;
import punctuatedEquilibrium.Phenotype;
import punctuatedEquilibrium.PhenotypeFactory;

public class IndividualTest {

	Individual	individual;

	// TODO refactor tests
	@Before
	public void setUp() {
		individual = IndividualFactory.getStandardIndividual();
	}

	@Test
	public void testCreate() {
		assertNotNull(individual);
	}

	@Test
	public void testCreateWithTraits() {
		Phenotype traits = PhenotypeFactory.getStandardPhenotype();
		IndividualParameters parameters = IndividualParameterFactory
				.standardParameters();
		individual = new Individual(traits, parameters);
		assertNotNull(individual);
	}

	@Test
	public void testFailedReproduction() {
		Deencapsulation.setField(individual, "probabilityOfSurvival", 0);
		individual.tryToReproduce();
		assertFalse(individual.isAlive());
	}

	@Test
	public void testIsAlive() {
		assertTrue(individual.isAlive());
	}

	@Test
	public void testIsDead() {
		Deencapsulation.setField(individual, "alive", false);
		assertFalse(individual.isAlive());
	}

	@Test
	public void testReportTraits() {
		Phenotype phenotype = PhenotypeFactory.getStandardPhenotype();
		IndividualParameters parameters = IndividualParameterFactory
				.standardParameters();
		individual = new Individual(phenotype, parameters);
		assertTrue(phenotype.isEquivalent(individual.reportTraits()));
	}

	@Test
	public void testSuccessfulReproduction() {
		Deencapsulation.setField(individual, "probabilityOfSurvival", 1);
		individual.tryToReproduce();
		assertTrue(individual.isAlive());
	}
}
